package com.parking.mgr.common.factory;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * @ClassName PageFactory
 * @Description 默认分页参数构建
 * @Auther: zhijianpu
 * @Date: 2023/5/18
 */
public class PageFactory {

    /**
     * 每页大小（默认20）
     */
    private static final String PAGE_SIZE_PARAM_NAME = "pageSize";

    /**
     * 第几页（从1开始）
     */
    private static final String PAGE_NO_PARAM_NAME = "pageNo";

    public static final long PAGE_NO_PARAM = 1L;

    public static final long PAGE_SIZE_PARAM = 10L;

    /**
     * 默认分页，在使用时PageFactory.defaultPage会自动获取pageSize和pageNo参数
     */
    public static <T> Page<T> defaultPage(Long pageSize, Long pageNo) {

        long pageSizeData = PAGE_SIZE_PARAM;
        long pageNoData = PAGE_NO_PARAM;

        //HttpServletRequest request = HttpServletUtil.getRequest();

        //每页条数
//        String pageSizeString = request.getParameter(PAGE_SIZE_PARAM_NAME);
        if (ObjectUtil.isNull(pageSize)) {
            pageSize = PAGE_SIZE_PARAM;
        }
//
//        //第几页
//        String pageNoString = request.getParameter(PAGE_NO_PARAM_NAME);
        if (ObjectUtil.isNull(pageNo)) {
            pageNo = PAGE_NO_PARAM;
        }

        return new Page<>(pageNo, pageSize);
    }
}
